<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增sys_email')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-email-add">
            <h4 class="form-header h4">sys_email信息</h4>
            <div class="form-group">    
                <label class="col-sm-3 control-label">邮件名称：</label>
                <div class="col-sm-8">
                    <input name="emailName" class="form-control" type="text">
                </div>
            </div>
            <input name="emailDept" type="hidden" id="treeId"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属部门</label>
                <div class="col-sm-8">
                    <input name="emailDept" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">收件人：</label>
                <div class="col-sm-8">
                    <!--<input name="inId" class="form-control" type="text">-->
                    <select name="inId" id="inId" class="form-control" >
                        <option th:each="item,info:${user}" th:object="${item}" th:value="*{userId}">
                            <span th:text="*{userName}"></span>
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发件人：</label>
                <div class="col-sm-8">
                    <input name="outId" class="form-control" th:value="${sysUser.userId}"  type="hidden">
                    <span th:text="${sysUser.userName}"></span>
                   <!-- <select name="outId" id="outId" class="form-control" disabled>
                        <option th:value="${sysUser.userId}"  th:text="${sysUser.userName}"></option>
                    </select>-->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发件时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="outTime" class="form-control localTime" disabled placeholder="自动获取当前时间" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">信件类型：</label>
                <div class="col-sm-8">
                    <select name="type" id="type" class="form-control">
                        <option value="0">普通信件</option>
                        <option value="1">机密信件</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">信件内容：</label>
                <div class="col-sm-8">
                    <textarea name="text" class="form-control"></textarea>
                </div>
            </div>
            <div class="btn btn-circle">
                <button onclick="submitHandler()">发送</button>
            </div>
            <div class="btn btn-circle">
                <button onclick="saveHandler()">暂存</button>
            </div>
            <div class="form-group" style="visibility: hidden">
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="createTime" class="form-control createTime"  type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group" style="visibility: hidden">
                <label class="col-sm-3 control-label">信件状态：</label>
                <div class="col-sm-8">
                    <select name="state" id="state">
                        <option value="1">未读</option>
                    </select>
                </div>
            </div>

            <div class="form-group" style="visibility: hidden">
                <label class="col-sm-3 control-label">信件位置：</label>
                <div class="col-sm-8">
                    <select name="local" id="local">
                        <option value="1">发件/收件</option>
                    </select>
                </div>
            </div>
            <div class="form-group" style="visibility: hidden">
                <label class="col-sm-3 control-label">在发件人垃圾箱：</label>
                <div class="col-sm-8">
                    <select name="outCrush" id="outCrush">
                        <option value="0">不在发件垃圾箱</option>
                    </select>
                </div>
            </div>
            <div class="form-group" style="visibility: hidden">
                <label class="col-sm-3 control-label">在收件人垃圾箱：</label>
                <div class="col-sm-8">
                    <select name="inCrush" id="inCrush">
                        <option value="0">不在收件垃圾箱</option>
                    </select>
                </div>
            </div>


        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/email"
        $("#form-email-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            $('.localTime').val(getNowTime())
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-email-add').serialize());
            }
        }

        function saveHandler() {
            $('.localTime').val(getNowTime())
            $('.createTime').val(getNowTime())
            if ($.validate.form()) {
                $.operate.save(prefix + "/save", $('#form-email-add').serialize());
            }
        }


        $("input[name='createTime'],input[name='outTime']").datetimepicker({
            format: "yyyy-mm-dd HH:mm:ss",
            minView: "month",
            autoclose: true
        });

        $(function() {
            console.log(getNowTime());
        })


        //获取当前时间
        function getNowTime() {
            var date = new Date();
            //年 getFullYear()：四位数字返回年份
            var year = date.getFullYear();  //getFullYear()代替getYear()
            //月 getMonth()：0 ~ 11
            var month = date.getMonth() + 1;
            //日 getDate()：(1 ~ 31)
            var day = date.getDate();
            //时 getHours()：(0 ~ 23)
            var hour = date.getHours();
            //分 getMinutes()： (0 ~ 59)
            var minute = date.getMinutes();
            //秒 getSeconds()：(0 ~ 59)
            var second = date.getSeconds();

            var time = year + '-' + addZero(month) + '-' + addZero(day) + ' ' + addZero(hour) + ':' + addZero(minute) + ':' + addZero(second);
            return time;
        }


        //小于10的拼接上0字符串
        function addZero(s) {
            return s < 10 ? ('0' + s) : s;
        }

        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            console.log(deptId)
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    </script>
</body>
</html>